from hashlib import md5
import rsa
# 单向加密
h=md5()
h.update('潭州课堂'.encode())
print(h.hexdigest())
# 双向加密
# 构造秘钥
publickKey,privateKey=rsa.newkeys(987)

enc=rsa.encrypt('潭州课堂'.encode(),publickKey)
print(enc)
byte=rsa.decrypt(enc,privateKey).decode()
print(byte)

# 加签验签
publickKey,privateKey=rsa.newkeys(666)

text='极度恐慌'
sign=rsa.sign(text.encode(),privateKey,'SHA-1')

print(sign)
print(publickKey.save_pkcs1().decode())
text1='极度恐荒'
print(rsa.verify(text.encode(),sign,publickKey))
result=rsa.verify(text1.encode(),sign,publickKey)
print(result)
